/**
 * 6065. 按位与结果大于零的最长组合
 * https://leetcode.cn/contest/weekly-contest-293/problems/largest-combination-with-bitwise-and-greater-than-zero/
 */

/**
 * @param {number[]} candidates
 * @return {number}
 */
function largestCombination(candidates) {
  let max = 0;
  let flag = 1;
  for (let i = 0; i < 24; i += 1, flag <<= 1) {
    let count = 0;
    for (let j = 0; j < candidates.length; j += 1) {
      if (candidates[j] & flag) {
        count += 1;
      }
    }
    max = Math.max(max, count);
  }
  return max;
}

console.log(largestCombination([16, 17, 71, 62, 12, 24, 14]) === 4);
console.log(largestCombination([8, 8]) === 2);
